//trade模块的小仓库
//引入接口文件
import { reqUserAddress, reqOrder } from '@/api'
const state = {
    userAddress: [],
    order: {}
};
const actions = {
    //通过api里的接口函数调用，向服务器发请求，获取服务器的数据
    //获取用户地址信息
    async userAddress({ commit }) {
        let res = await reqUserAddress();
        if (res.code == 200) {
            commit('USERADDRESS', res.data)
        } else {
            return Promise.reject(new Error('userAddress failed'))
        }
    },
    //获取订单交易信息
    async order({ commit }) {
        let res = await reqOrder();
        console.log(res);
        if (res.code == 200) {
            commit('ORDER', res.data)
        } else {
            return Promise.reject(new Error('order failed'))
        }
    },
    //提交订单，不使用vuex，换成在组件内进行请求
    // //提交订单
    // async submitOrder({ commit }, { query, data }) {
    //     let res = await resSubmitOrder(query, data);
    //     console.log(res);
    // }

};
const mutations = {
    USERADDRESS(state, userAddress) {
        state.userAddress = userAddress
    },
    ORDER(state, order) {
        state.order = order
    }
};

const getters = {
    detailArrayList(state) {
        return state.order.detailArrayList || []
    },
    orderDetailVoList(state) {
        return state.order.orderDetailVoList || []
    }
};

export default {
    state,
    mutations,
    actions,
    getters
}